<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="/static/base/static/css/login.css"/>
    <link rel="stylesheet" href="/static/webjars/layui/css/layui.css" />
    <script type="text/javascript" src="/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
    <title>智慧兴文城乡公共信息平台</title>
</head>
<body>
<div id="container">
    <div id="bd">
        <div class="login">
            <div class="login-top"><h1 class="logo"></h1></div>
            <div class="login-input">
                <p class="user ue-clear">
                    <label>用户名</label>
                    <input name="tel" type="text" autocomplete="off"   placeholder="请输入用户名"/>
                </p>
                <p class="password ue-clear">
                    <label>密码</label>
                    <input name="check" type="password" autocomplete="off"  placeholder="请输入密码"/>
                    <%--<button city-send class="btn layui-btn layui-btn-sm">发送</button>--%>
                    <%--<button class="btn layui-btn layui-btn-sm layui-btn-disabled">50&nbsp;S</button>--%>
                </p>
                <p class="password ue-clear">
                    <label>验证码</label>
                    <input name="code" type="text" autocomplete="off" maxlength="4" placeholder="请输入验证码"/>
                    <img id="code"  src="/api/auth/getImage" onclick="javascript:changeImg()" />
                </p>

            </div>
            <div class="login-btn ue-clear">
                <a href="javascript:void(0)" class="btn" city-click="login" id="submitLogin">登录</a>
                <div class="remember ue-clear">
                    <%--<a class="forget" href="/can't_get"><label for="submitLogin">收不到验证码？</label></a>--%>
                    <%--<a class="forget" href="javascript:void(0)"><label for="submitLogin">收不到校验码？</label></a>--%>
                </div>
            </div>
        </div>
    </div>
</div>

<%--测试项目--%>
<div id="ft">四川省数聚汇智科技有限公司&nbsp;版权所有&nbsp;&nbsp;CopyRight&nbsp;2018&nbsp;&nbsp;蜀ICP备12345678号</div>
</body>
<script type="text/javascript" src="/static/webjars/layui/layui.all.js"></script>
<script type="text/javascript">
    var height = $(window).height();
    $("#container").height(height);
    $("#bd").css("padding-top", height / 2 - $("#bd").height() / 2);

    $(window).resize(function () {
        var height = $(window).height();
        $("#bd").css("padding-top", $(window).height() / 2 - $("#bd").height() / 2);
        $("#container").height(height);

    });
</script>

<script type="text/javascript">
    var layer = layui.layer;
    var system = "${system}";

    <%--验证码刷新--%>
    function changeImg(){
        document.getElementById("code").src = "/api/auth/getImage?date=" + new Date();
    }

    <%--接收不到随机码--%>
    $(".forget").click(function(){
        layer.alert("请确认手机账号是否正确！",{
            title:"接受不到随机码"
        });
    });

    <%--发送校验码--%>
    $("button[city-send]").click(function(){
        var that = $(this)
            ,code = $("input[name=code]").val()
            ,tel = $("input[name=tel]").val();

        if(that.hasClass("layui-btn-disabled")){return false;}
        if(!isPoneAvailable(tel)){layer.alert("手机号码不符合规则");return false};


    });

    <%--&lt;%&ndash;检测手机号码是否符合规则&ndash;%&gt;--%>
    <%--function isPoneAvailable(str) {--%>
        <%--var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;--%>
        <%--return myreg.test(str);--%>
    <%--}--%>

    <%--验证登陆--%>
    $("a[city-click=login]").click(function(){
        var code = $("input[name=code]").val()
        <%--验证码确认--%>
        $.post(
            "/api/auth/validImage",{
                code:code
            },function(res){
                <%--先修改验证码--%>
                changeImg();
                if(res != "200"){
                    layer.alert("验证码错误！");
                }else{
                    // that.html("发送中..");
                    //                    // $.post("/api/auth/send",{
                    //                    //     tel:tel
                    //                    // },function(res){
                    //                    //     if(res == "200"){
                    //                    //         layer.msg("短信已发送，请注意查收！");
                    //                    //         that.addClass("layui-btn-disabled");
                    //                    //         that.html("已发送");
                    //                    //     }else{
                    //                    //         that.html("发送");
                    //                    //         layer.alert(res);
                    //                    //     }
                    //                    // });
                    var checkCode  = $("input[name=check]").val();
                    var tel  = $("input[name=tel]").val();
                    $.post("/api/auth/checkCode",{
                        checkCode:checkCode,
                        tel:tel
                    },function(res){
                        if(res.code === 1){
                            var data = res.data;
                            layer.alert("登陆成功！",{},function(){
                                $.cookie("sign",data.sign);
                                window.location.href = "/home.html?system=" +system;
                            });
                        }
                        else
                            layer.alert(res.msg);
                    });
                }
            }
        );



    });

</script>
</html>